package day24;

import org.junit.Test;

import java.io.*;

public class Demo3 {
    public static void main(String[] args) throws IOException {
        FileReader fr = new FileReader("D:\\a\\abc.txt");
        int n = fr.read();
        System.out.println(n);
        char[] c = new char[5];
        fr.read(c);
        System.out.println(new String(c));
        fr.close();
        FileWriter fw = new FileWriter("D:\\a\\abc.txt");
        fw.write(97);
        fw.write('o');
        fw.write('k');
        fw.write("中道崩殂");
        fw.close();

        FileReader fr1 = new FileReader("D:\\a\\abc.txt");
        FileWriter fw1 = new FileWriter("D:\\a\\abc2.txt");
        char[] cs = new char[1024];
        int len = 0;
        while ((len = fr1.read(cs)) != -1) {
            fw1.write(cs, 0, len);
        }
        fr1.close();
        fw1.close();
    }

    @Test
    public void test() throws IOException {
        try (FileReader fr = new FileReader("D:/a/abc.mp4");
             FileWriter fw = new FileWriter("D:/a/abc5.mp4");
             BufferedReader br = new BufferedReader(fr);
             BufferedWriter bw = new BufferedWriter(fw)){
            String s;
            while ((s=br.readLine())!=null) {
                bw.write(s);
            }

        }catch (IOException e){
            e.printStackTrace();
        }
    }
}

